<template>
	<view class="wrap">
		<u-form class="form" :model="model" :rules="rules" ref="uForm" label-position="left">
			<u-form-item label="客户姓名" prop="cusName" label-width="180">
				<u-input placeholder="请输入客户姓名" v-model="model.cusName" type="text" maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="客户年龄" prop="cusAge" label-width="180">
				<u-input placeholder="请输入客户年龄" v-model="model.cusAge" type="text" maxlength="16"></u-input>
			</u-form-item>
			<u-form-item label="客户性别" prop="cusSex" label-width="180">
				<u-input placeholder="请输入客户性别" v-model="model.cusSex" type="text" maxlength="5"></u-input>
			</u-form-item>
			<u-form-item label="客户联系方式" prop="cusPhone" label-width="180">
				<u-input placeholder="请输入客户联系方式" v-model="model.cusPhone" type="text" maxlength="24"></u-input>
			</u-form-item>
			<u-form-item label="客户住址" prop="cusAddress" label-width="180">
				<u-input placeholder="请输入客户住址" v-model="model.cusAddress" type="text" maxlength="32"></u-input>
			</u-form-item>
			<u-form-item label="详细地址" prop="cusAddressDetail" label-width="180">
				<u-input placeholder="请输入详细地址" v-model="model.cusAddressDetail" type="text" maxlength="256"></u-input>
			</u-form-item>
			<u-form-item label="客户身份证号" prop="cusIdCard" label-width="180">
				<u-input placeholder="请输入客户身份证号" v-model="model.cusIdCard" type="text" maxlength="18"></u-input>
			</u-form-item>
			<u-form-item label="删除标识 0-未删除，1-已删除" prop="delFlag" label-width="180">
				<u-input placeholder="请输入删除标识 0-未删除，1-已删除" v-model="model.delFlag" type="text" maxlength="2"></u-input>
			</u-form-item>
			<u-form-item label="停用标识 0-未停用，1-停用" prop="stopFlag" label-width="180">
				<u-input placeholder="请输入停用标识 0-未停用，1-停用" v-model="model.stopFlag" type="text" maxlength="2"></u-input>
			</u-form-item>
			<u-form-item label="上传图片" prop="images" label-position="top">
				<js-uploadfile v-model="model.dataMap" :biz-key="model.id" biz-type="tcustomer_image"></js-uploadfile>
			</u-form-item>
		</u-form>
		<view class="form-footer">
			<u-button class="btn" type="primary" @click="submit">提交</u-button>
			<!-- <u-button class="btn" type="default" @click="cancel">关闭</u-button> -->
		</view>
	</view>
</template>
<script>
/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
export default {
	data() {
		return {
			model: {
				id: '',
				cusName: '',
				cusAge: '',
				cusSex: '',
				cusPhone: '',
				cusAddress: '',
				cusAddressDetail: '',
				cusIdCard: '',
				delFlag: '',
				stopFlag: '',
			},
			rules: {
				'delFlag': [
					{
						required: true,
						message: '请输入删除标识 0-未删除，1-已删除',
						trigger: ['change','blur'],
					}
				],
				'stopFlag': [
					{
						required: true,
						message: '请输入停用标识 0-未停用，1-停用',
						trigger: ['change','blur'],
					}
				],
			},
		};
	},
	onLoad(params){
		this.$u.api.tcustomer.form(params).then(res => {
			Object.assign(this.model, res.tcustomer);
			this.$refs.uForm.setRules(this.rules);
		});
	},
	methods: {
		submit() {
			this.$refs.uForm.validate(valid => {
				if (valid) {
					// console.log('tcustomer-save: ' + JSON.stringify(this.model));
					this.$u.api.tcustomer.save(this.model).then(res => {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
							success: function () {
								if (res.result == 'true') {
									uni.setStorageSync('refreshList', true);
									uni.navigateBack();
								}
							}
						});
					});
				} else {
					this.$u.toast('您填写的信息有误，请根据提示修正。');
				}
			});
		},
		cancel() {
			uni.navigateBack();
		}
	}
};
</script>
<style lang="scss">

</style>
